/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.jr.swb.rest.mq.handlers;

import cn.ac.iie.di.ban.jr.swb.rest.mq.global.GlobalParas;
import cn.ac.iie.di.ban.jr.swb.rest.mq.utils.FileAppender;
import cn.ac.iie.di.ban.jr.swb.rest.mq.utils.SenderPool;
import cn.ac.iie.di.datadock.rdata.exchange.client.exception.REConnectionException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

/**
 *
 * @author Administrator
 */
public class TimeTask extends TimerTask {

    public static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(TimeTask.class);

    public TimeTask() {

    }

    @Override
    public void run() {
        try {
            //每小时get一次
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
            String dateNowStr = sdf.format(date);
            logger.info("start" + GlobalParas.FILE_DIR + "wbyq_hourhot_" + dateNowStr + GlobalParas.FILE_SIZE + GlobalParas.FILE_TIMEOUT);
            FileAppender fileAppender = new FileAppender(GlobalParas.FILE_DIR, "wbyq_hourhot_" + dateNowStr, GlobalParas.FILE_SIZE, GlobalParas.FILE_TIMEOUT);
            fileAppender.start();
            //1.热门微博(t_hot_microblog)接口（每小时获取一次，每小时的热门微博可能会有重s复的）
            Hotwb_Handler hotwbHandler = new Hotwb_Handler("hot_microblog", new SenderPool("", ""), fileAppender, GlobalParas.THOT_COLUMNS_NAME_LIST, GlobalParas.THOT_COLUMNS_TYPE_LIST);
            hotwbHandler.execute();
            //2.大V热门微博(t_vhot_microblog)接口（每小时获取一次，每小时的热门微博可能会有重复的）
            Hotwb_Handler vhotwbHandler = new Hotwb_Handler("vhot_microblog", new SenderPool("", ""), fileAppender, GlobalParas.TVHOT_COLUMNS_NAME_LIST, GlobalParas.TVHOT_COLUMNS_TYPE_LIST);
            vhotwbHandler.execute();
            //3.热门话题（综合t_ multiple_topic）（每小时获取一次，hot_huati字段有很多值，华宇是分成了多条记录存储）
            Hotwb_Handler multiple_topicHandler = new Hotwb_Handler("multiple_topic", new SenderPool("", ""), fileAppender, GlobalParas.TMHOT_COLUMNS_NAME_LIST, GlobalParas.TMHOT_COLUMNS_TYPE_LIST);
            multiple_topicHandler.execute();
            //4.热门话题（分类t_class_topic）
            Hotwb_Handler class_topicHandler = new Hotwb_Handler("class_topic", new SenderPool("", ""), fileAppender, GlobalParas.TCHOT_COLUMNS_NAME_LIST, GlobalParas.TCHOT_COLUMNS_TYPE_LIST);
            class_topicHandler.execute();
            //5热搜词(t_hot_search)
            Hotwb_Handler hot_searchHandler = new Hotwb_Handler("hot_search", new SenderPool("", ""), fileAppender, GlobalParas.TSHOT_COLUMNS_NAME_LIST, GlobalParas.TSHOT_COLUMNS_TYPE_LIST);
            hot_searchHandler.execute();
            //8.在线用户数(t_online_user)（参考下代码）(每小时获取一次)
            Hotwb_Handler online_userHandler = new Hotwb_Handler("online_user", new SenderPool("", ""), fileAppender, GlobalParas.TOLUS_COLUMNS_NAME_LIST, GlobalParas.TOLUS_COLUMNS_TYPE_LIST);
            online_userHandler.execute();
            //每天5点get一次
            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");//设置日期格式
            String dfDate = df.format(date);
            //6.日原创微博量(t_orig_microblog)
            Hotwb_Handler orig_microblogHandler = new Hotwb_Handler("orig_microblog", new SenderPool("", ""), fileAppender, GlobalParas.TORIG_COLUMNS_NAME_LIST, GlobalParas.TORIG_COLUMNS_TYPE_LIST);
            orig_microblogHandler.execute();
            //7.大V日原创微博量(t_vorig_microblog)
            Hotwb_Handler vorig_microblogHandler = new Hotwb_Handler("vorig_microblog", new SenderPool("", ""), fileAppender, GlobalParas.TVORIG_COLUMNS_NAME_LIST, GlobalParas.TVORIG_COLUMNS_TYPE_LIST);
            vorig_microblogHandler.execute();
            fileAppender.stop();
        } catch (IOException ex) {
            logger.error(ex.getMessage(), ex);
        } catch (REConnectionException ex) {
            logger.error(ex.getMessage(), ex);
        }
    }

}
